<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>首页</title>
    <base href="<%=basePath%>">



    <style type="text/css">
      #maindiv{
        margin: 0 auto;
        width: 300px;
        text-align:center;
        border:2px solid #a1a1a1;
        padding:10px 40px;
        background:#dddddd;
        border-radius:25px;
        -moz-border-radius:25px; /* 老的 Firefox */
      }
    </style>

    <script src="<%=basePath%>plug_in/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">

        $(function () {
            $.ajax({
                url:"<%=basePath%>api/test/grid",
                type:"POST",
                cache:false,
                async:false,
                data:{"type":"1"},
                dataType:"json",
                success:function(data){
                    if(data){
                        var list = data.data;
                        var appendHtml = "";
                        for(var i = 0;i<list.length;i++){
                            var model = list[i];
                            var id = model.id;
                            var name = model.name;
                            var title = model.title;
                            var num = model.num;
                            appendHtml += '<tr id="'+id+'" align="center"><td>'+id+'</td><td>'+name+'</td><td>'+title+'</td><td>'+num+'</td>' +
                                '<td><input type="button" onclick="upt(\''+id+'\')" value="修改" />&nbsp;&nbsp;' +
                                '<input type="button" onclick="del(\''+id+'\')" value="删除" /></td><tr>';
                        }
                        $("#t_table").append(appendHtml);
                    }
                }
            });
        });


        function upt(id) {
            location.href = "<%=basePath%>/api/test/jump?load=opt&id="+id;
        }
        function add() {
            location.href = "<%=basePath%>/api/test/jump?load=add";
        }
        function del(id) {
            $.ajax({
                url:"<%=basePath%>api/test/delete",
                type:"POST",
                cache:false,
                async:false,
                data:{"id":id},
                dataType:"json",
                success:function(data){
                    alert('删除成功');
                    $("#"+id).remove();
                }
            });
        }
    </script>

  </head>
  <body>


  <center><h1>Spring MVC + Hibernate 的 maven 版本 测试 </h1></center>

  <table id="t_table" border="1" style="width: 80%">
    <tr>
      <td colspan="5"><input type="button" value="添加" onclick="add()"  /></td>
    </tr>
    <tr align="center">
      <td>ID</td><td>name</td><td>title</td><td>num</td><td>操作</td>
    </tr>
  </table>




  </body>

</html>
